<?php
/**
 * [商网通 System] Copyright swtshop.cn
 * QQ: 1170787711
 * Author: gj.name
 * This is NOT a freeware
*/
defined('IN_UQ') or exit('Access Denied');
class connect_uqcms extends control
{
    function __construct()
    {
        $this->uid = $_SESSION['user']['uid'];
        parent::__construct();
    }
    public function index()
    {
        $row['connect_avatar'] = "http://qzapp.qlogo.cn/qzapp/111111/942FEA70050EEAFBD4DCE2C1FC775E56/50";
        $row['connect_nick'] = "我是小义乌";
        $this->assign('row', $row);
        $this->display('index/connect_show');
    }
    function index_save()
    {
        $username = trim($_POST['username']);
        $password = trim($_POST['password']);
        $again_password = trim($_POST['again_password']);
        if ($password == $again_password) {
            if (verfiy::is_email($username)) {
                $data['username'] = $username;
                $data['password'] = $this->module('user')->password_hash($password);
                $this->db->update(table('member'), $data, 'where  = ' . $_SESSION['connect']['appid']);
            } else {
                exit('必须为电子邮件格式！');
            }
        } else {
            exit('两次密码不一致！');
        }
    }
    public function qq()
    {
        $_SESSION['user_connect']['state'] = rand('1000000', '100000000000');
        $data['response_type'] = 'code';
        $data['client_id'] = $this->_CFG['connect_qq_app_id'];
        $data['scope'] = 'get_user_info';
        $data['redirect_uri'] = '?m=connect&a=qq_callback';
        $data['state'] = $_SESSION['user_connect']['state'];
        $url = 'https://graph.qq.com/oauth2.0/authorize?' . http_build_query($data);
        location($url);
    }
    public function qq_callback()
    {
        $code = $_GET['code'] ? $_GET['code'] : exit('连接错误！');
        $state = $_GET['state'] ? $_GET['state'] : exit('状态错误!');
    }
    public function weibo()
    {
        $data['client_id'] = $this->_CFG['connect_weibo_app_id'];
        $data['response_type'] = 'code';
        $data['redirect_uri'] = '?m=connect&a=weibo_callback';
        $url = 'https://api.weibo.com/oauth2/authorize?' . http_build_query($data);
        location($url);
    }
    public function wchat()
    {
    }
    public function connect()
    {
    }
}